<?php

if (!defined('__BACKEND__'))
    die("you cannot directly access this page");
/*
 * by SONY K Wibisono
 * e-mail : sony@sonywibisono.com
 */
global $action,$user_id,$login_status,$is_admin,$mod;
_showMenuHeader();
//Place code here
function listpreferences(){
    global $db,$site_name,$site_description,$site_keyword;
    echo "<form action=\"?mod=panel&file=prefs\" method=\"post\">
        <input type='hidden' name='action' value='save_pref'/>";
    $sender=  get_preference('email_sender');
       ?> 

<div id="table_data">
    <h2>Web Site Preferences</h2>
<table width="100%" cellpadding="4" cellspacing="2">
    <?php
    $sql="select * from preferences order by pref_name";
    $result=$db->query($sql);
    while ($row=$db->fetch_array($result)){
        extract($row);
        $label=str_replace("_"," ",$pref_name);
        if (strpos($pref_name,"password")>0){
            $type="password";
        } else $type="text";
        echo "<tr><td class='field_name'>$label</td><td> <img class='icon' src=\"images/ic_help.png\" title=\"$description\"/></td>
            <td><input class=\"textbox\"
        type=\"$type\" name=\"$pref_name\" value=\"$pref_value\" size=\"".  strlen($pref_value)."\"/></td></tr>\r\n";
    }
    ?>
   <tr><td colspan="2">&nbsp;</td><td align="right"><input type="submit" value="Save" class="button"/></tr>
</table></div>
<?php
echo "</form>";
}
function savepreferences(){
    global $db,$_POST;
    $sql="select * from preferences order by pref_name";
    $result=$db->query($sql);
    while ($row=$db->fetch_array($result)){
        extract($row);
        $sql_update="update preferences set pref_value='".$_POST[$pref_name]."'
                    where pref_name='$pref_name'";
        //echo "$sql_update<br/>";
        $db->query($sql_update);
    }
    refresh_to("?mod=panel&file=prefs", "Back to Preference", 1);
}
global $action;
switch ($action){
    case 'save_pref':
        savepreferences();
        break;
    default:
        listpreferences();
}
?>
<p align="center">
<a href="?mod=panel"><img src="images/back_button.png" title="Back To Control Panel"/></a></p>